Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub oracleTest()
    Dim cn As ADODB.Connection
    Dim str As String
    Dim ts As Tasks
    Dim t As Task
    
    ' set connection and task variables
    Set cn = New ADODB.Connection
    Set ts = ActiveProject.Tasks
    
    str = "Provider = MSDAORA.1;Password=" & "lisro" & _
                     ";User ID=" & "lisro" & ";Data Source=" & "fanying" & ";Persist Security Info=True"
    
    cn.Open str
    
    Open "C:\tttt.txt" For Output As #1
	Print #1, "truncate table wzp_project; \n commit;"
    n = 0
    
    For Each t In ts
        If Not t Is Nothing Then
            
         ' insert into oracle
          a = Split(t.WBS, ".")
            
            
                       
           Ln = UBound(a) - LBound(a)
            
            
            
           If t.Name <> "" Then
                If Ln = 0 Then
                     If Asc(Mid(t.Name, 1, 1)) < 0 Then
                         ID = 0
                     Else
                         ID = Mid(t.Name, 1, 4)
                     End If
                     
                     
                            If Asc(Mid(t.Name, 1, 1)) < 0 Then
                              
                              ' MsgBox t.WBS & t.Name
                            End If
                End If
                    
           End If
           
           indexT = Array(0, 0, 0, 0, 0, 0, 0)
           
           
            For ii = 0 To Ln
                If Ln = 0 Then
                    indexT(0) = a(0)
                Else
                    indexT(ii) = a(ii)
                End If
                
                
            Next ii
            
            
           If n > 11110 Then
                ' Exit Sub
            End If
            
            
            If ID <> 0 Then
               Print #1, "insert into wzp_project (id, t_Name ,t_Duration,t_Start,t_Finish,t_Predecessors," & _
                        "t_ResourceNames,t_ResourceGroup,t_Notes,t_PercentComplete,t_Text2,t_Text20,t1,t2,t3,t4,t5,t6)  " & _
                            "values('" & ID & "','" & t.Name & "','" & t.Duration & "','" & t.Start & "','" & _
                               t.Finish & "','" & t.Predecessors & "','" & t.ResourceNames & "','" & _
                                 t.ResourceGroup & "','" & t.Notes & "','" & t.PercentComplete & "','" & t.Text2 & "','" & t.Text20 & "','" & _
                                     indexT(0) & "','" & indexT(1) & "','" & indexT(2) & "','" & indexT(3) & "','" & indexT(4) & "','" & indexT(5) & "');"
            End If
        
        End If
        n = n + 1
        
    Next t
    Print #1, "commit;"
    Close #1
    
    
    
End Sub


